home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / lh211src.zip / SELF.C < prev    next >
C/C++ Source or Header  |  1991-03-02  |  2KB  |  110 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <farstr.h>
  5. #include <dos.h>
  6. #include "sfx.h"
  7. #include "lh.h"
  8. #include "intrface.h"
  9. #include "errmes.h"
  10. #include "disp.h"
  11.  
  12. struct exe_header {
  13.     ushort    id;
  14.     ushort    last;
  15.     ushort    size;
  16.     ushort    relsize;
  17.     ushort    hdrsize;
  18.     ushort    minalloc;
  19.     ushort    maxalloc;
  20.     ushort    initss;
  21.     ushort    initsp;
  22.     ushort    sum;
  23.     ushort    initip;
  24.     ushort    initcs;
  25.     ushort    reloffset;
  26.     ushort    overlay;
  27.     ushort    dummy0;
  28.     ushort    dummy1;
  29. } exehdr = 
  30. {0x5a4d, (A_endofcode + sizeof(exehdr)) & 0x01ff, 
  31.                  (A_endofcode + sizeof(exehdr) + 0x01ff) / 0x0200, 
  32.                          0x0000, 0x0002, 0x1000, 0xffff, 0xfff0,
  33.  0x0100, 0x0000, 0x0100, 0xfff0, 0x001c, 0x0000, 0x0000, 0x0000};
  34.  
  35. char nojump[] = "\xeb\x01";
  36.  
  37. void initsfx(void)
  38. {
  39.     char *p, *q;
  40.  
  41.     p = getfilename(filename1);
  42.     q = strchr(p, '.');
  43.     if (q) *q = '\0';
  44.     strcpy(filename1, p);
  45.     strcat(filename1, ".EXE");
  46.  
  47.     extract_internal(NULL, sfx);
  48.     if (flg_x == 0) {
  49.         exehdr.last = (A_endofshort + sizeof(exehdr)) & 0x01ff;
  50.         exehdr.size = (A_endofshort + sizeof(exehdr) + 0x01ff) / 0x0200;
  51.         text[A_subver] = 'S';
  52.         strcpy(&text[A_getopt - 3], nojump);
  53.         *(ushort *)&text[A_seeksize - 2] = A_endofshort + sizeof(exehdr);
  54.         strcpy(&text[A_extended - 3], nojump);    /* memcpy(,,3) */
  55.         strcpy(&text[A_setattr - 3], nojump);
  56.         strcpy(&text[A_autoexec - 3], nojump);
  57.     }
  58.     strcpy(&text[A_myself], filename1);
  59.     fwrite(&exehdr, sizeof(exehdr), 1, file2);
  60.     fwrite(text, flg_x ? A_endofcode : A_endofshort, 1, file2);
  61. }
  62.  
  63. int copysfx(void)
  64. {
  65.     char *p;
  66.     char c;
  67.  
  68.     p = &hpb.method[3];
  69.     if (flg_x == 0) hpb.pathname = hpb.filename;
  70.     dispalone("Extract");
  71.     c = *p; *p = ' ';
  72.     if (memcmp(hpb.method, "-lh -", 5) || strchr("045", c) == NULL) {
  73.         eprintf(" : %s\n", METHODERR);
  74.         return 0;
  75.     }
  76.     *p = c;
  77.     hpb.level = 0;
  78.     update_arcstamp();
  79.     makehdr();
  80.     writehdr();
  81.     copyfile(file1, file2, hpb.packed, 0);
  82.     eprintf("\n");
  83.     return 1;
  84. }
  85.  
  86. void makesfx(char far *bdir)
  87. {
  88.     uint attr;
  89.     int yn;
  90.  
  91.     fclose(file1);
  92.     far_strcpy(arcname, bdir);
  93.     strcat(arcname, getfilename(filename1));
  94.     strcpy(filename1, arcname);
  95.     if (_dos_getfileattr(arcname, &attr) == 0) {
  96.         yn = 'Y';
  97.         if (flg_m == 0) {
  98.             eprintf("\n%s : %s\n%s", arcname, SAMEFILE, OVERWT);
  99.             yn = getyn();
  100.         }
  101.         if (yn == 'N') {
  102.             fclose(file2);
  103.             remove(filename2);
  104.             file2 = NULL;
  105.         } else {
  106.             if (remove(arcname)) error(RDONLY, arcname);
  107.         }
  108.     }
  109. }
  110.